<?php 
/**
  * Created by hkun
  * Email: 350839123@qq.com
  * Date: 2020-04-13
  */

namespace app\api\model\v2\cms;
use app\api\model\BaseModel;
use traits\model\SoftDelete;

class CmsVideo extends BaseModel {
	use SoftDelete;
	protected $deleteTime = 'delete_time';
	protected $hidden=['delete_time','update_time','create_time'];
	protected $autoWriteTimestamp = true;
	/**
	  * 方法说明 - 模型关联 video-img
	  */
	public function videoImg(){
	    return $this->hasOne('app\api\model\Image','id','video_img_id')->bind(['video_img_url'=> 'url']);
	}
	
	public function add_item($title,$jump_url,$video_img_id)
	{
	    $this->title = $title;
	    $this->jump_url = $jump_url;
	    $this->video_img_id = $video_img_id;
	    $this->show = 1;
		if($this->save()){
			return $this;
		}else{
			return false;
		}
	}
	
	public function video_list_get($show){
		if($show){
			$result = self::with(['videoImg'])->where('show',$show)->order('id desc')->select()->hidden(['banner_img']);
		}else{
			$result = self::with(['videoImg'])->order('id desc')->select()->hidden(['video_img']);
		}
		return $result;
	}
	
	public function video_change_show($id,$show){
		$result = self::where('id',$id)->find();
		$result->show = $show;
		$result->save();
		return $result;
	}
	
	public function get_video_detail($id){
		$result = self::with(['videoImg'])->where('id',$id)->find();
		return $result;
	}
}
?>